package net.valerijtimakov.homefinances.dao.storages.finances.mysql;

import java.util.Map;

import net.valerijtimakov.homefinances.domain.common.DataItem;
import net.valerijtimakov.homefinances.domain.finances.CurrencyItem;
import net.valerijtimakov.homefinances.exceptions.AppExceptionWrongState;
import net.valerijtimakov.homefinances.exceptions.AppPersProviderException;
import net.valerijtimakov.homefinances.exceptions.AppPersistentException;
import net.valerijtimakov.homefinances.exceptions.wrongarg.AppExceptionNullArgument;
import net.valerijtimakov.homefinances.dao.storages.common.mysql.NamedItemsStorage;
import net.valerijtimakov.homefinances.dao.storages.finances.ICurrencyStorage;

public class CurrencyStorage extends NamedItemsStorage implements ICurrencyStorage {

	public CurrencyStorage(IMySqlProvider provider) throws AppExceptionWrongState {
		super(provider);
	}

	public Map<Long, CurrencyItem> getAllCurrencies() throws AppPersProviderException, AppExceptionWrongState {
		initSelect();
		selectQuery.setSelectAll(true);
		return getMap();
	}

	public Map<Long, CurrencyItem> getCurrencies(long... id) throws AppPersProviderException, AppExceptionWrongState {
		return getItemsByIds(id);
	}

	public void addCurrency(CurrencyItem item) throws AppExceptionNullArgument, AppExceptionWrongState, AppPersistentException {
		addItem(item, "Не задан экземпляр валюты!", "Ошибка добавления валюты!");
	}

	public void removeCurrency(long id) throws AppPersProviderException, AppExceptionWrongState {
		delete(id);
	}

	public void updateCurrency(CurrencyItem item) throws AppPersProviderException, AppExceptionWrongState {
		update(item);
	}

	@Override
	protected String getTableName() {
		return "currency";
	}

	@Override
	protected DataItem createTempItem() {
		return new CurrencyItem();
	}

}
